package com.cheng.reggie.mapper;

import com.cheng.reggie.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.Calendar;
import java.util.List;

public interface CategoryMapper {


    //分页查询(方式:分表查) : 第二条sql,根据类别id查询类别对象
    @Select("select * from category where id=#{id}")
    Category findById(Long id);

    //删除指定类别
    @Delete("DELETE  FROM  category WHERE id=#{id}")
    Integer deleteById(Long id);

    //新增菜品分类
    @Insert(" INSERT INTO category VALUES (null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save (Category categorye);

    //根据类别名称查询
    @Select("SELECT  * FROM category WHERE name=#{name}")
    Category findName(String name);

    //查询所有的类别
    @Select("SELECT * FROM category ORDER BY sort ASC ")
    List<Category> findAll();

    //修改类别
    Integer updateById(Category category);

    //根据类别名称查询类别,排除自己
    @Select("SELECT * FROM category WHERE name=#{name} and id !=#{id}")
    Category findByName2(Category category);

    //根据类型查询类别列表数据
    List<Category> findAllByType(@Param("type") Integer type);
}
